<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }} - 股票新闻分析系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>

<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="/">股票新闻分析系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="/">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/dashboard">仪表盘</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="/reports">策略报告</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/llm_analysis">大模型分析</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2>{{ report.title }}</h2>
            <span class="badge bg-primary">日期: {{ report.date }}</span>
        </div>

        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h4 class="card-title mb-0">市场概览</h4>
            </div>
            <div class="card-body">
                <p>{{ report.market_overview }}</p>
                <div class="d-flex justify-content-between">
                    <span class="badge bg-info">整体趋势: {{ report.market_trend }}</span>
                    <span class="badge bg-warning">风险等级: {{ report.risk_level }}</span>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="card mb-4">
                    <div class="card-header bg-success text-white">
                        <h4 class="card-title mb-0">投资建议</h4>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="card">
                                    <div class="card-header bg-success text-white">
                                        <h5 class="card-title mb-0">买入建议</h5>
                                    </div>
                                    <div class="card-body">
                                        <ul class="list-group">
                                            {% for rec in report.recommendations %}
                                            {% if rec.action == '买入' %}
                                            <li class="list-group-item">
                                                <div class="d-flex w-100 justify-content-between">
                                                    <h6 class="mb-1">{{ rec.stock_name }} ({{ rec.stock_code }})</h6>
                                                    <span class="badge bg-success">买入</span>
                                                </div>
                                                <p class="mb-1">行业: {{ rec.industry }}</p>
                                                <p class="mb-1">预期收益: {{ rec.expected_return }}</p>
                                                <p class="mb-1">持有时间: {{ rec.holding_period }}</p>
                                                <div class="progress">
                                                    <div class="progress-bar bg-success" role="progressbar"
                                                        style="width: {{ rec.confidence * 100 }}%"
                                                        aria-valuenow="{{ rec.confidence * 100 }}" aria-valuemin="0"
                                                        aria-valuemax="100">{{ rec.confidence * 100 }}%</div>
                                                </div>
                                            </li>
                                            {% endif %}
                                            {% endfor %}
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card">
                                    <div class="card-header bg-warning text-white">
                                        <h5 class="card-title mb-0">持有建议</h5>
                                    </div>
                                    <div class="card-body">
                                        <ul class="list-group">
                                            {% for rec in report.recommendations %}
                                            {% if rec.action == '持有' %}
                                            <li class="list-group-item">
                                                <div class="d-flex w-100 justify-content-between">
                                                    <h6 class="mb-1">{{ rec.stock_name }} ({{ rec.stock_code }})</h6>
                                                    <span class="badge bg-warning">持有</span>
                                                </div>
                                                <p class="mb-1">行业: {{ rec.industry }}</p>
                                                <p class="mb-1">预期波动: {{ rec.expected_fluctuation }}</p>
                                                <p class="mb-1">持有时间: {{ rec.holding_period }}</p>
                                                <div class="progress">
                                                    <div class="progress-bar bg-warning" role="progressbar"
                                                        style="width: {{ rec.confidence * 100 }}%"
                                                        aria-valuenow="{{ rec.confidence * 100 }}" aria-valuemin="0"
                                                        aria-valuemax="100">{{ rec.confidence * 100 }}%</div>
                                                </div>
                                            </li>
                                            {% endif %}
                                            {% endfor %}
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card">
                                    <div class="card-header bg-danger text-white">
                                        <h5 class="card-title mb-0">卖出建议</h5>
                                    </div>
                                    <div class="card-body">
                                        <ul class="list-group">
                                            {% for rec in report.recommendations %}
                                            {% if rec.action == '卖出' %}
                                            <li class="list-group-item">
                                                <div class="d-flex w-100 justify-content-between">
                                                    <h6 class="mb-1">{{ rec.stock_name }} ({{ rec.stock_code }})</h6>
                                                    <span class="badge bg-danger">卖出</span>
                                                </div>
                                                <p class="mb-1">行业: {{ rec.industry }}</p>
                                                <p class="mb-1">预期损失: {{ rec.expected_loss }}</p>
                                                <p class="mb-1">建议时间: {{ rec.selling_time }}</p>
                                                <div class="progress">
                                                    <div class="progress-bar bg-danger" role="progressbar"
                                                        style="width: {{ rec.confidence * 100 }}%"
                                                        aria-valuenow="{{ rec.confidence * 100 }}" aria-valuemin="0"
                                                        aria-valuemax="100">{{ rec.confidence * 100 }}%</div>
                                                </div>
                                            </li>
                                            {% endif %}
                                            {% endfor %}
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="card mb-4">
            <div class="card-header bg-info text-white">
                <h4 class="card-title mb-0">行业分析</h4>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <canvas id="industryChart"></canvas>
                    </div>
                    <div class="col-md-6">
                        <h5>行业趋势分析</h5>
                        <ul class="list-group">
                            {% for industry in report.industry_analysis %}
                            <li class="list-group-item d-flex justify-content-between align-items-center">
                                {{ industry.name }}
                                {% if industry.trend == '上涨' %}
                                <span class="badge bg-success rounded-pill">上涨</span>
                                {% elif industry.trend == '下跌' %}
                                <span class="badge bg-danger rounded-pill">下跌</span>
                                {% else %}
                                <span class="badge bg-warning rounded-pill">稳定</span>
                                {% endif %}
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="card mb-4">
            <div class="card-header bg-secondary text-white">
                <h4 class="card-title mb-0">风险提示</h4>
            </div>
            <div class="card-body">
                <ul class="list-group">
                    {% for risk in report.risk_warnings %}
                    <li class="list-group-item">{{ risk }}</li>
                    {% endfor %}
                </ul>
            </div>
        </div>

        <div class="d-grid gap-2 d-md-flex justify-content-md-end mb-4">
            <a href="/reports" class="btn btn-secondary me-md-2">返回报告列表</a>
            <button class="btn btn-primary" onclick="window.print()">打印报告</button>
            <button class="btn btn-success" id="shareBtn">分享报告</button>
        </div>
    </div>

    <footer class="bg-dark text-white text-center py-3 mt-5">
        <div class="container">
            <p class="mb-0">股票新闻分析系统 &copy; 2025 版权所有</p>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 行业分析图表
        const industryData = {{ report.industry_analysis| tojson }};
        const industryNames = industryData.map(item => item.name);
        const industryScores = industryData.map(item => item.score);
        const industryColors = industryData.map(item => {
            if (item.trend === '上涨') return 'rgba(40, 167, 69, 0.7)';
            if (item.trend === '下跌') return 'rgba(220, 53, 69, 0.7)';
            return 'rgba(255, 193, 7, 0.7)';
        });

        const ctx = document.getElementById('industryChart').getContext('2d');
        new Chart(ctx, {
            type: 'bar',
            data: {
                labels: industryNames,
                datasets: [{
                    label: '行业趋势分值',
                    data: industryScores,
                    backgroundColor: industryColors,
                    borderColor: industryColors.map(color => color.replace('0.7', '1')),
                    borderWidth: 1
                }]
            },
            options: {
                responsive: true,
                scales: {
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });

        // 分享功能
        document.getElementById('shareBtn').addEventListener('click', function () {
            // 这里可以实现分享功能，例如生成分享链接或二维码
            alert('分享功能正在开发中，敬请期待！');
        });
    </script>
</body>

</html>